package com.xcx.demo.service;

import com.xcx.demo.dao.ProductDAO;
import com.xcx.demo.entity.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import javax.persistence.PreUpdate;
import java.util.List;

@Service
public class ProductService {

    @Autowired
    ProductDAO productDAO;

    public List<Product> list(){
        return productDAO.findAll();
    }

    public Product findById(Integer id){
        return productDAO.findById(id).orElse(null);
    }

    public boolean isExist(Integer id){
        Product product=productDAO.findById(id).orElse(null);
        return null!=product;
    }

    public List<Product> search(String keywords){
        return productDAO.findAllByTitleLikeOrDescLike("%"+keywords+"%","%"+keywords+"%");
    }
}
